import json
import cv2 as cv
import matplotlib.pyplot as plt
import matplotlib.image as mpimg # mpimg 用于读取图片
from PIL import Image
import numpy as np


with open('./boxes.json','r',encoding='utf8')as fp:
    json_data = json.load(fp)

    boxes = json_data["boxes"]
    for i in range(len(boxes)):
        if boxes[i]["name"] == "box_b":
            rectangle = boxes[i]["rectangle"]
            left_top = rectangle["left_top"]
            right_bottom = rectangle["right_bottom"]

    print(left_top)
    print(right_bottom)




Img1 = cv.imread('baobei.jpg')
Img1 = np.array(Img1)
Img1 = Img1[:,:,::-1]

size = (right_bottom[0]-left_top[0],right_bottom[1]-left_top[1])
Img2 = cv.imread('aote.png')
Img2 = np.array(Img2)
Img2 = cv.resize(Img2,size,interpolation=cv.INTER_CUBIC)


print(np.shape(Img2))

Img3 = Img1

for i in range(np.shape(Img2)[0]):
    for j in range(np.shape(Img2)[1]):
        for k in range(np.shape(Img2)[2]):
            Img3[left_top[0]+i,left_top[1]+j,k] = Img2[i,j,k]




plt.imshow(Img3)
plt.show()

